package huawei;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * 大雁的叫声
 */
public class Dayan {

    private static String quack = "quack";

    public static void main(String[] args) {

        String s = "quackssquackafffzzqquuaaccckkzz";

        while (s.length() <= 1000) {
            s += s;
        }

        s = s.substring(0, 1000);

        Set<Integer> set = new HashSet<>();

        for (int i = 0; i < s.length(); i++) {
            if (set.contains(i)) continue;

            List<Integer> list = new ArrayList<>(); // 现在用过的字符
            for (int j = i; j < s.length(); j++) {
                if (!set.contains(j) && quack.charAt(list.size()) == s.charAt(j)) {
                    list.add(j);
                    if (list.size() == 5) {
                        set.addAll(list);
                        break;
                    }
                }
            }
        }

        System.out.println(set.size() / 5);
    }
}
